using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

namespace THSERP.BaseProvider
{
    public class BaseClassFactory
    {
        public static Type GetClassType(String strClassName)
        {
            try
            {
                Assembly THSBase = Assembly.GetExecutingAssembly();
                Type type = THSBase.GetType(strClassName);
                if (type != null)
                    return type;
                type = THSApp.THSERPAssembly.GetType(strClassName);
                if (type != null)
                    return type;
                Assembly THSLib = Assembly.LoadFrom(Application.StartupPath + "\\THSLib.dll");
                type = THSLib.GetType(strClassName);
                return type;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }
        }

        public static object GetClass(String strClassName)
        {
            Type type = GetClassType(strClassName);
            if (type != null)
            {
                object obj = type.InvokeMember("", BindingFlags.CreateInstance, null, null, null);
                return obj;
            }
            return null;
        }
    }
}
